// @copyright 2017-2018 zzu_softboy <zzu_softboy@163.com>
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Created by softboy on 2018/01/18.

#include "gtest/gtest.h"
#include "pdk/stdext/preprocessor/Arithmetic.h"
#include "pdk/stdext/preprocessor/config/Limits.h"

// addition
TEST(ArithmeticTest, testAdd)
{
   ASSERT_EQ(PDK_PP_ADD(2, 3), 5);
   ASSERT_EQ(PDK_PP_ADD(PDK_PP_ADD(2, 2), 2), 6);
   ASSERT_EQ(PDK_PP_ADD(2, PDK_PP_ADD(1, 4)), 7);
   ASSERT_EQ(PDK_PP_ADD(PDK_PP_ADD(2, 2), PDK_PP_ADD(2, 2)), 8);
}


TEST(ArithmeticTest, testSub)
{
   ASSERT_EQ(PDK_PP_SUB(11, 0), 11);
   ASSERT_EQ(PDK_PP_SUB(12, 1), 11);
   ASSERT_EQ(PDK_PP_SUB(3, 4), 0);
   ASSERT_EQ(PDK_PP_SUB(PDK_PP_SUB(10, 5), 2), 3);
   ASSERT_EQ(PDK_PP_SUB(PDK_PP_SUB(7, 3), PDK_PP_SUB(10, 8)), 2);
}

TEST(ArithmeticTest, testMul)
{
   ASSERT_EQ(PDK_PP_MUL(0, 1), 0);
   ASSERT_EQ(PDK_PP_MUL(1, 0), 0);
   ASSERT_EQ(PDK_PP_MUL(1, 1), 1);
   ASSERT_EQ(PDK_PP_MUL(4, 3), 12);
   
   ASSERT_EQ(PDK_PP_MUL(PDK_PP_MUL(2, 2), 2), 8);
   ASSERT_EQ(PDK_PP_MUL(2, PDK_PP_MUL(2, 2)), 8);
   ASSERT_EQ(PDK_PP_MUL(PDK_PP_MUL(2, 2), PDK_PP_MUL(2, 2)), 16);
}

TEST(ArithmeticTest, testDivision)
{
   ASSERT_EQ(PDK_PP_DIV(2, 1), 2);
   ASSERT_EQ(PDK_PP_DIV(0, 5), 0);
   ASSERT_EQ(PDK_PP_DIV(7, 3), 2);
   ASSERT_EQ(PDK_PP_DIV(PDK_PP_DIV(4, 2), 2), 1);
   ASSERT_EQ(PDK_PP_DIV(10, PDK_PP_DIV(10, 2)), 2);
   ASSERT_EQ(PDK_PP_DIV(PDK_PP_DIV(10, 2), PDK_PP_DIV(4, 2)), 2);
}

TEST(ArithmeticTest, testModuls)
{
   ASSERT_EQ(PDK_PP_MOD(5, 5), 0);
   ASSERT_EQ(PDK_PP_MOD(9, 5), 4);
   ASSERT_EQ(PDK_PP_MOD(7, 4), 3);
   ASSERT_EQ(PDK_PP_MOD(PDK_PP_MOD(5, 3), 3), 2);
   ASSERT_EQ(PDK_PP_MOD(5, PDK_PP_MOD(4, 3)), 0);
}

TEST(ArithmeticTest, testIncrement)
{
   ASSERT_EQ(PDK_PP_INC(0), 1);
   ASSERT_EQ(PDK_PP_INC(22), 23);
   ASSERT_EQ(PDK_PP_INC(256), 256);
   
   ASSERT_EQ(PDK_PP_INC(PDK_PP_INC(0)), 2);
   ASSERT_EQ(PDK_PP_INC(PDK_PP_INC(19)), 21);
   ASSERT_EQ(PDK_PP_INC(PDK_PP_INC(255)), 256);
}

TEST(ArithmeticTest, testDecrement)
{
   ASSERT_EQ(PDK_PP_DEC(0), 0);
   ASSERT_EQ(PDK_PP_DEC(22), 21);
   ASSERT_EQ(PDK_PP_DEC(256), 255);
   
   ASSERT_EQ(PDK_PP_DEC(PDK_PP_DEC(0)), 0);
   ASSERT_EQ(PDK_PP_DEC(PDK_PP_DEC(19)), 17);
   ASSERT_EQ(PDK_PP_DEC(PDK_PP_DEC(256)), 254);
   ASSERT_EQ(PDK_PP_DEC(PDK_PP_DEC(1)), 0);
}
